package com.yqy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import pojo.User;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ParamTestController {
    @RequestMapping("/param/servletAPI")
    public String getParamByServletAPI(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username="+username+"&password="+password);
        return "success";
    }

    @RequestMapping("/param/sameName")
    public String getParamBySameName(String username,String password){
        System.out.println("username="+username+"&password="+password);
        return "success";
    }

    @RequestMapping("/param/MoreSameName")
    public String getParamByMoreSameName(String[] username){
        System.out.println("username1="+username[0]);
        System.out.println("username2="+username[1]);
        System.out.println("username3="+username[2]);
        return "success";
    }

    @RequestMapping("/param/RequestPram")
    public String getParamByRequestPramAnnotation(
            @RequestParam(value = "username",required = false,defaultValue = "cxk") String name,
            @RequestHeader(value="referer") String refererValue,
            @CookieValue(value="JSESSIONID") String jsessionid
    ){
        System.out.println("name="+name);
        System.out.println("refererValue="+refererValue);
        System.out.println("jsessionid="+jsessionid);
        return "success";
    }

    @RequestMapping("/param/pojo")
    public String getParamByPojo(User user){
        System.out.println(user);
        return "success";
    }
}
